<?php
class Invoice extends CI_Controller{
	private $data;
	public function __construct(){
		parent::__construct();
		if(!Auth::isLoggedIn()) redirect("/");
		$this->load->model("model_invoice");
	}
	
	
	
	public function index($set="sot"){
		
		$data['javascript'][] = "hitung.js";
		$data['active_invoice'] = 'y';
		$data['title'] = TITLE.' - Lihat Daftar Invoice'; 
		$data['invoice'] = $this->model_invoice->getInvoiceList();
		$check = $this->input->post('invoviewcheck');
		if($this->input->post("btnGener") ){
			if(empty($check))
			{
				redirect("/invoice/index/err");
			}
			
				$this->generateMultiPdf();
			/*if($hasil){ 
				 $data['success'] = "Invoice Berhasil di Buat";
				 $data['max1'] = $this->model_invoice->checkInvoice();
				 $this->load->view("invoAdd",$data);
			};*/
			
		}
		if($set=="set"){
			$data['success'] = "Invoice Berhasil Di Generate";
		}
		else if($set=="err"){
			$data['success'] = "Error, harus dipilih salah satu";
		}
		$this->load->view("viewinvoice",$data);
	}
	
	
	public function generateMultiPdf(){
		$h = 0;
		$addr ="";
		$checkbox = $this->input->post('invoviewcheck');
		
		foreach($checkbox as $check){
			
				$h++;
				$addr = $addr . "/" . $check;
			
		}
		//var_dump($checkbox);
		
		redirect("/Pdfprinter/pdfMultiPrint/".$h . $addr );
	}
	
	function ajaxSearchInvoice(){
		$jenisPencarian = $_POST['pilih'];
		$dicari = $_POST['nilai'];
		$status = $_POST['status'];
		$duestatus = $_POST['duestatus'];
		$mode = $_POST['mymode'];
		$data['invoice'] = $this->model_invoice->ajaxGetSearch($jenisPencarian, $dicari, $status, $duestatus);
		$data['debug'] = $jenisPencarian;
		$this->load->view("invoAjaxSearchRes", $data);
		
		
		
	}
	
	
	function ajaxAddBayar(){
		$bayar = $_POST['bayar'];
		$tanggal = $_POST['tanggal'];
		$melalui = $_POST['melalui'];
		$noInvo = $_POST['noInvo'];
		$total = $_POST['total'];
		$duedate = $_POST['duedate'];
		$this->model_invoice->addBayar($bayar, $tanggal, $melalui, $noInvo, $total, $duedate);
	}
	
	function ajaxLoadView(){
		$invoice = $_POST['noInvo'];
		$data['invoice'] = $this->model_invoice->getDataInvo($invoice);
		$this->load->view("invoViewAjaxLoad",$data);
	}
	
	
	/* INVOICE EDIT*/
	public function edit(){
		$data['active_invoice'] = 'y';
		$noinvo =$this->uri->segment(3, 0);
		$sFlag =  $this->uri->segment(4, 0);
		$data['invoice'] = $this->model_invoice->getInvoDet1($noinvo);
		$data['item'] = $this->model_invoice->getItem($noinvo);
		$data['title'] = TITLE.' - Buat Invoice';
		$data['owner'] = $this->model_invoice->getOwnerList();
		$data['driver'] = $this->model_invoice->getDriverList();
		$data['max'] = $this->model_invoice->checkInvoice();
		$data['invoTambah'] = explode("INV", $data['max']);
		$data['customer'] = $this->model_invoice->getCustomerList();
		$data['perusahaan']=$this->model_invoice->getPtList();
		$data['staff']=$this->model_invoice->getStaffList();
		$data['payterm']=$this->model_invoice->getPayTerms();
		$invoice = $data['max'];
		

		if($this->input->post("btnSave") ){
			
			$hasil = $this->_editInvoice();
			if($hasil){
				 
				
				 redirect('/invoice/edit/' .$data['invoice']['0']['invoice_no'] .'/s', 'refresh');
			};
			
		}
		if($sFlag!=""){
			$data['success'] = "Data Berhasil Di Ubah";
		}
		
		$this->load->view("invoEdit",$data);
	}
	
	function _editInvoice(){
		//$this->form_validation->set_message('_checkpassword', 'Current Password is incorrect');
		//$this->form_validation->set_message('_check_default', 'Harus dipilih salah satu');
		/*$this->form_validation->set_message('_checkDateKembali', 
											'Tanggal kembali lebih cepat dari tanggal pinjam');
		$this->form_validation->set_message('_checkDateSewa', 'Tidak ada mobil tersedia pada tanggal tersebut');*/
		$this->form_validation->set_error_delimiters('', '');
		$config = array(
               	array(
                     'field'   => 'mataUang',
                     'label'   => 'Nama Perusahaan',
                     'rules'   => 'trim|xss_clean'
                  ),
			 	/*array(
                     'field'   => 'customer',
                     'label'   => 'Nama Peminjam',
                     'rules'   => 'trim|required|xss_clean'
                  ),
				array(
                     'field'   => 'supir',
                     'label'   => 'Nama Supir',
                     'rules'   => 'trim|required|xss_clean'
                  ),
               	array(
                     'field'   => 'telepon_peminjam',
                     'label'   => 'Telepon Peminjam',
                     'rules'   => 'trim|required|xss_clean'
                  ),
				array(
                     'field'   => 'tanggal_pinjam',
                     'label'   => 'Tanggal Pinjam',
                     'rules'   => 'trim|required|xss_clean|callback__checkDateSewa[]'
                  ),
				array(
                     'field'   => 'tanggal_kembali',
                     'label'   => 'Tanggal Kembali',
                     'rules'   => 'trim|required|xss_clean|callback__checkDateKembali['.$this->input->post('tanggal_pinjam').']'
                  ),
				array(
                     'field'   => 'ownerName',
                     'label'   => 'Nama Pemilik',
                     'rules'   => 'trim|required|callback__check_default|xss_clean'
                  ),
				 array(
                     'field'   => 'carList1',
                     'label'   => 'Mobil yang Dipakai',
                     'rules'   => 'trim|required|callback__check_default|xss_clean'
                  ),
				array(
                     'field'   => 'penerimaan',
                     'label'   => 'Penerimaan',
                     'rules'   => 'trim|required|integer|xss_clean'
                  )*/
            );

		$this->form_validation->set_rules($config); 
		
		if ($this->form_validation->run() == FALSE){
			
			return false;
			
		}
		else{
			//save to database..
			$this->model_invoice->editInvoice();
			return true;
		}
	}	
	
	/* INVOICE ADD by So*/
	public function add_invoice_bySO(){
		$this->load->model("model_sales");
		$data['active_invoice'] = 'y';
		$noSO =$this->uri->segment(3, 0);
		$data['invoice'] = $this->model_sales->getSODet($noSO);
		$data['item'] = $this->model_sales->getItem($noSO);
		$data['title'] = TITLE.' - Buat Invoice Dari Sales Order';
		$data['owner'] = $this->model_invoice->getOwnerList();
		$data['driver'] = $this->model_invoice->getDriverList();
		$data['max'] = $this->model_invoice->checkInvoice();
		$data['invoTambah'] = explode("INV", $data['max']);
		$data['customer'] = $this->model_invoice->getCustomerList();
		$data['perusahaan']=$this->model_invoice->getPtList();
		$data['staff']=$this->model_invoice->getStaffList();
		$data['payterm']=$this->model_invoice->getPayTerms();
		$data['noso'] = $noSO;
		$invoice = $data['max'];
		

		if($this->input->post("btnSave") ){
			
			$hasil = $this->_createInvoice();
			if($hasil){
				 $data['success'] = "Invoice Berhasil di Buat";
				 $data['max1'] = $this->model_invoice->checkInvoice();
			};
			
		}
		else if($this->input->post("btnGener") ){
			$hasil = $this->_createInvoice();
			if($hasil){
				 $data['success'] = "Invoice Berhasil di Buat";
				 $data['max1'] = $this->model_invoice->checkInvoice();
				 $this->load->view("invoAdd",$data);
			};
			redirect("/Pdfprinter/pdfPrint/".$invoice. "/" . $this->input->post("mataUang", true) . "/" 
						. $this->input->post("customer", true) . "/" . $this->input->post("dateNow", true). "/" 
						. $this->input->post("salesPerson", true) . "/" . $this->input->post("delivDate", true). "/" 
						. $this->input->post("shipto", true) . "/" . $this->input->post("billto", true). "/"
						. $this->input->post("delivTerm", true) . "/" . $this->input->post("payterm", true). "/"
						. $this->input->post("ptName", true) . "/" . $this->input->post("order", true) . "/edit" 
						);
			//$this->pdfPrint($data['max']);
			
			
		}
		$this->load->view("invoAddBySO",$data);
	}
	/* INVOICE ADD*/
	public function add_invoice($set="sot"){
		$data['active_invoice'] = 'y';
		$data['title'] = TITLE.' - Buat Invoice';
		$data['owner'] = $this->model_invoice->getOwnerList();
		$data['driver'] = $this->model_invoice->getDriverList();
		$data['max'] = $this->model_invoice->checkInvoice();
		$data['invoTambah'] = explode("INV", $data['max']);
		$data['customer'] = $this->model_invoice->getCustomerList();
		$data['perusahaan']=$this->model_invoice->getPtList();
		$data['staff']=$this->model_invoice->getStaffList();
		$data['payterm']=$this->model_invoice->getPayTerms();
		$invoice = $data['max'];
		if($set=="set"){
			$data['success'] = "Invoice Berhasil Di Generate";
		}

		if($this->input->post("btnSave") ){
			
			$hasil = $this->_createInvoice();
			if($hasil){
				 $data['success'] = "Invoice Berhasil di Buat";
				 $data['max1'] = $this->model_invoice->checkInvoice();
				 
			};
			
		}
		else if($this->input->post("btnGener") ){
			$hasil = $this->_createInvoice();
			if($hasil){
				 $data['success'] = "Invoice Berhasil di Buat";
				 $data['max1'] = $this->model_invoice->checkInvoice();
				 $this->load->view("invoAdd",$data);
			};
			redirect("/Pdfprinter/pdfPrint/".$invoice. "/" . $this->input->post("mataUang", true) . "/" 
						. $this->input->post("customer", true) . "/" . $this->input->post("dateNow", true). "/" 
						. $this->input->post("salesPerson", true) . "/" . $this->input->post("delivDate", true). "/" 
						. $this->input->post("shipto", true) . "/" . $this->input->post("billto", true). "/"
						. $this->input->post("delivTerm", true) . "/" . $this->input->post("payterm", true). "/"
						. $this->input->post("ptName", true) . "/" . $this->input->post("order", true). "/add"
						);
			//$this->pdfPrint($data['max']);
			
			
		}
		$this->load->view("invoAdd",$data);
	}
	
	
	function _createInvoice(){
		//$this->form_validation->set_message('_checkpassword', 'Current Password is incorrect');
		//$this->form_validation->set_message('_check_default', 'Harus dipilih salah satu');
		/*$this->form_validation->set_message('_checkDateKembali', 
											'Tanggal kembali lebih cepat dari tanggal pinjam');
		$this->form_validation->set_message('_checkDateSewa', 'Tidak ada mobil tersedia pada tanggal tersebut');*/
		$this->form_validation->set_error_delimiters('', '');
		$config = array(
               	array(
                     'field'   => 'mataUang',
                     'label'   => 'Nama Perusahaan',
                     'rules'   => 'trim|xss_clean'
                  ),
			 	/*array(
                     'field'   => 'customer',
                     'label'   => 'Nama Peminjam',
                     'rules'   => 'trim|required|xss_clean'
                  ),
				array(
                     'field'   => 'supir',
                     'label'   => 'Nama Supir',
                     'rules'   => 'trim|required|xss_clean'
                  ),
               	array(
                     'field'   => 'telepon_peminjam',
                     'label'   => 'Telepon Peminjam',
                     'rules'   => 'trim|required|xss_clean'
                  ),
				array(
                     'field'   => 'tanggal_pinjam',
                     'label'   => 'Tanggal Pinjam',
                     'rules'   => 'trim|required|xss_clean|callback__checkDateSewa[]'
                  ),
				array(
                     'field'   => 'tanggal_kembali',
                     'label'   => 'Tanggal Kembali',
                     'rules'   => 'trim|required|xss_clean|callback__checkDateKembali['.$this->input->post('tanggal_pinjam').']'
                  ),
				array(
                     'field'   => 'ownerName',
                     'label'   => 'Nama Pemilik',
                     'rules'   => 'trim|required|callback__check_default|xss_clean'
                  ),
				 array(
                     'field'   => 'carList1',
                     'label'   => 'Mobil yang Dipakai',
                     'rules'   => 'trim|required|callback__check_default|xss_clean'
                  ),
				array(
                     'field'   => 'penerimaan',
                     'label'   => 'Penerimaan',
                     'rules'   => 'trim|required|integer|xss_clean'
                  )*/
            );

		$this->form_validation->set_rules($config); 
		
		if ($this->form_validation->run() == FALSE){
			
			return false;
			
		}
		else{
			//save to database..
			$this->model_invoice->addInvoice();
			return true;
		}
	}	
	
	function invoAjaxSearchBarangCar(){
		
		$dicari = $_POST['nilai'];
		
		
		$mode = $_POST['mymode'];
		$data['car'] = $this->model_invoice->ajaxGetBarangMobilSearch($dicari);
		
		$this->load->view("invoCarAjaxSearchRes", $data);
		
		
		
	}
	
	function invoAjaxSearchBarangDriver(){
		
		$dicari = $_POST['nilai'];
		
		
		$mode = $_POST['mymode'];
		$data['barang'] = $this->model_invoice->ajaxGetBarangDriverSearch($dicari);
		
		$this->load->view("invoDriverAjaxSearchRes", $data);
		
		
		
	}
	function _check_default($post_string)
	{
		if($post_string == '0'){
			return false;
			
		}else{
			return true;
		}
	}

	function _checkDateKembali($kembali, $pinjam){
		$kembali = strtotime($kembali);
		$pinjam = strtotime($pinjam);
		if($pinjam>$kembali){
			
			return false;
			
		}
		return true;
	}
	function ajaxLoadCarList(){
		$owner_id = $_POST['car'];
		$mode = $_POST['mymode'];
		$data['carList'] = $this->model_invoice->getCarList($owner_id);
		$this->load->view("carlist", $data);	
	}
	
	function ajaxLoadInvoDet(){
		$invo_id = $_POST['id'];
		$mode = $_POST['mymode'];
		$data['invoDet'] = $this->model_invoice->getInvoDet($invo_id);
		$this->load->view("invoDet", $data);	
	}
	
	
	function _checkDateSewa($tgl_pinjam){
		$salah = 0;
		$id_mobil = $this->input->post("carList1",true);
		$data = $this->model_invoice->checkPinjam($id_mobil);
		$tgl_pinjam = strtotime($tgl_pinjam);
		$tgl_kembali = strtotime($this->input->post('tgl_kembali'));
		foreach($data as $data1){
			$data1['tgl_mulai'] = strtotime($data1['tgl_mulai']);
			$data1['tgl_akhir'] = strtotime($data1['tgl_akhir']);
			if(($tgl_pinjam>=$data1['tgl_mulai'])&&($tgl_kembali<=$data1['tgl_akhir'])){
				return true;
			}			
		}
		return false;
	}
	
	function ajakLoadCarPlat(){
		$car_id = $_POST['plat'];
		$result = $this->model_invoice->getCarPlat($car_id);
		echo $result;	
	}
	function ajaxLoadCustList(){
		$ptId = $_POST['perusahaan'];
		$mode = $_POST['mymode'];
		$data['debug'] = $ptId = $_POST['perusahaan'];
		$data['debug1'] =$ptId;
		$data['customer2'] = $this->model_invoice->ajaxGetCustomerList($ptId, $mode);
		$this->load->view("invoiceAddAjaxCustList", $data);
	}
	function ajaxLoadCustDeliv(){
		$cuId = $_POST['customer'];
		
		$data['debug'] = $_POST['customer'];
		$data['debug1'] =$cuId;
		$data['customer2'] = $this->model_invoice->ajaxGetCustomerDeliv($cuId);
		$this->load->view("invoiceAddAjaxCustDeliv", $data);
	}
	
	function ajaxLoadCustBill(){
		$cuId = $_POST['customer'];
		
		$data['debug'] =  $_POST['customer'];
		$data['debug1'] =$cuId;
		$data['customer2'] = $this->model_invoice->ajaxGetCustomerBill($cuId);
		$this->load->view("invoiceAddAjaxCustBill", $data);
	}
	
	function ajaxLoadPayTerm(){
		$data['payterm']=$this->model_invoice->getPayTerms();
		$this->load->view("invoiceAddAjaxPayTermList", $data);
	}
	
	function ajaxLoadSalesPerson(){
		$data['staff']=$this->model_invoice->getStaffList();
		$this->load->view("invoiceAddAjaxSalesList", $data);
	}
	
	function ajaxTanggalAdd(){
		$tanggal = $this->uri->segment(3, 0);
		$tambah = $this->uri->segment(4, 0);;
		$dateCreate = strtotime($tanggal);
		$dateCreate = $dateCreate + (24*3600*$tambah);
		$data['dateCreate1'] = date('d-M-Y', $dateCreate);
		$this->load->view("invoiceAddTanggalTambah", $data);
	}
	
	function ajaxLoadBarang(){
		
		$jenisBarang = $_POST['perusahaan'];
		$mode = $_POST['mymode'];
		if($jenisBarang == "supir"){
			$data['barang'] = $this->model_invoice->ajaxGetBarangSupir();
		
			$this->load->view("invoAjaxLoadSupir", $data);
		}
		else{
			$data['car'] = $this->model_invoice->ajaxGetBarangMobil($jenisBarang, $mode);
			$this->load->view("invoAjaxLoadMobil", $data);
		}
		
		
	}
	
	public function payAdd(){
		$data['debug1'] = "";
		if($this->input->post("btnSave") ){
			
			$hasil = $this->_addPayTerm();
						
		}
		$this->load->view("payTermAdd", $data);
	}
	
	function addPayTerm(){
		$bookn = $_POST['bookn'];
		$booki = $_POST['booki'];
		$this->model_invoice->addPayTerm($bookn, $booki);
	}
	function addCustTo(){
		$nama = $_POST['name'];
		$telp = $_POST['telp'];
		$fax = $_POST['fax'];
		$alamat = $_POST['alamat'];
		$rt = $_POST['rt'];
		$rw = $_POST['rw'];
		$kode = $_POST['kode'];
		$kota = $_POST['kota'];
		$provinsi = $_POST['provinsi'];
		$cuId = $_POST['custId'];
		$ptId = $_POST['ptId'];
		$this->model_invoice->addCustTo($nama, $telp, $fax, $alamat, $rt, $rw, $kode, $kota,$provinsi, $cuId, $ptId);
	}
	function addDelivTo(){
		$nama = $_POST['name'];
		$telp = $_POST['telp'];
		$fax = $_POST['fax'];
		$alamat = $_POST['alamat'];
		$rt = $_POST['rt'];
		$rw = $_POST['rw'];
		$kode = $_POST['kode'];
		$kota = $_POST['kota'];
		$provinsi = $_POST['provinsi'];
		$cuId = $_POST['custId'];
		$ptId = $_POST['ptId'];
		$this->model_invoice->addDelivTo($nama, $telp, $fax, $alamat, $rt, $rw, $kode, $kota,$provinsi, $cuId, $ptId);
	}
	function addBillTo(){
		$nama = $_POST['name'];
		$telp = $_POST['telp'];
		$fax = $_POST['fax'];
		$alamat = $_POST['alamat'];
		$rt = $_POST['rt'];
		$rw = $_POST['rw'];
		$kode = $_POST['kode'];
		$kota = $_POST['kota'];
		$provinsi = $_POST['provinsi'];
		$cuId = $_POST['custId'];
		$ptId = $_POST['ptId'];
		$this->model_invoice->addBillTo($nama, $telp, $fax, $alamat, $rt, $rw, $kode, $kota,$provinsi, $cuId, $ptId);
	}
	
	function addSales(){
		$username = $_POST['name'];
		$password = $_POST['telp'];
		$name = $_POST['fax'];
		$email = $_POST['alamat'];
		$phone = $_POST['rt'];
		$address = $_POST['rw'];
		
		$this->model_invoice->addSalesPerson($username, $password, $name, $email, $phone, $address);
	}
	function check_username(){
		$username = $_POST['username'];
		$data['value'] = $this->model_invoice->checkUsername($username);		
		$this->load->view("invoAddCheck", $data);
	}
	
	
	function pdfPrint()
	{
		
		$cuId = "asd";//$this->uri->segment(3, 0);
		$mataUang = "asd";//$this->uri->segment(4, 0);
		$idCustomer = "asd";//$this->uri->segment(5, 0);
		$dateNow = "asd";//$this->uri->segment(6, 0);
		$sales = "asd";//$this->uri->segment(7, 0);
		$delivDate = "asd";//$this->uri->segment(8, 0);
		$shipto = "asd";//$this->uri->segment(9, 0);
		$billto = "asd";//$this->uri->segment(10, 0);
		$delivTerm = "asd";//$this->uri->segment(11, 0);
		$payTerm = "asd";//$this->uri->segment(12, 0);
		$Ptname = "asd";//$this->uri->segment(13, 0);
		$orderno = "asd";//$this->uri->segment(14, 0);
		$ptDetail =  "asd";//$this->model_pdf->getPtDetail($Ptname);
		$Ptnamebesar = "asd";//$ptDetail['0']['pt_name'];
		$Ptnamebesar = "asd";//strtoupper($Ptnamebesar);
		$creator= "asd";//get_username($this->session->userdata("user_id"));
		$salesPerson= "asd";//get_username($sales);
		$billdetail = "asd";//$this->model_pdf->getBillDetail($billto);
		$delivdetail = "asd";//$this->model_pdf->getDelivDetail($shipto);
		$note = "asd";//$this->model_pdf->getNote($cuId);
		header("Content-type:application/pdf");
		header('Content-Disposition: attachment; filename="' . $cuId . '.pdf"');
		
		$this->load->library('cezpdf');
		//$this->load->library('cezpdf', array('paper' => 'a4','orientation' => 'potrait'));
		$this->load->helper('pdf_helper');	
		$datacreator = array (
                    'Title'=>'Invoice',
                    'Author'=>'Harpa',
                    'Subject'=>'Harpa Invoice',
                    'Creator'=>'Darius Sandatinus',
                    'Producer'=>'http://www.maestroglobal.biz'
                    );
		$this->cezpdf->addInfo($datacreator);
		
		
		
		
		$data = array(
			array('name'=>'<b>PT HARPA SEKAWAN</b>','type'=>'')
			,array('name'=>'Jl Cipinang Muara No. 47','type'=>'Creator: ' . $creator)
			,array('name'=>'Jakarta 13420','type'=>'')
			,array('name'=>'','type'=>'')
			,array('name'=>'','type'=>'')
			,array('name'=>'Tel: +6221 8195784  Fax:  +6221 8502527','type'=>'')
			,array('name'=>'Email: info@harpa.co.id','type'=>'Invoice No: '. $cuId)
			,array('name'=>'Website: www.harpa.co.id','type'=>'Currency: ' .$mataUang)
		);
		$this->cezpdf->ezTable($data
								,array('name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>400.28, 'col'=>array('justification'=>'right')));
		$this->cezpdf->setLineStyle(3, 'round');						
		$this->cezpdf->line(30,665,370,665);
		$this->cezpdf->addText(380,662,14,'Invoice');
		$this->cezpdf->line(430,665,570,665);
		
		$data1 = array(
			array('name'=>'','type'=>'')
		
			,array('name'=>'','type'=>'')
			,array('name'=>'','type'=>'')
			,array('name'=>'Bill To','type'=>'Delivery To')
			,array('name'=>'Mr./Ms. ' .$billdetail['0']['bill_name'],'type'=>'Mr./Ms. ' . $delivdetail['0']['ship_name'])
			,array('name'=>$Ptnamebesar,'type'=>$Ptnamebesar)
			,array('name'=>$billdetail['0']['bill_alamat'] . '   RT.0' . $billdetail['0']['bill_rt'] 
					. '   RW.0' . $billdetail['0']['bill_rw']
					,'type'=>$delivdetail['0']['ship_alamat'] . '   RT.0' . $delivdetail['0']['ship_rt'] 
					. '   RW.0' . $delivdetail['0']['ship_rw'])
			,array('name'=>$billdetail['0']['bill_kota'],'type'=>$delivdetail['0']['ship_kota'])
			,array('name'=>$billdetail['0']['bill_provinsi'] . ' - ' . $billdetail['0']['bill_kode']
					,'type'=>$delivdetail['0']['ship_provinsi'] . ' - ' . $delivdetail['0']['ship_kode'])
			,array('name'=>'','type'=>'')
			,array('name'=>'Phone: ' . $billdetail['0']['bill_telp'] . '    Fax: ' . $billdetail['0']['bill_fax']
					,'type'=>'Phone: ' . $delivdetail['0']['ship_telp']. '   Fax: '. $delivdetail['0']['ship_fax'])
			
		);
		$this->cezpdf->ezTable($data1
								,array('name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>530.28));
		
		$data2 = array(
			array('name'=>'Date','type'=>$dateNow, '3'=>'Order No', '4'=>$orderno,'5'=>'Sales Person', '6'=>$salesPerson)
		
			,array('name'=>'Delivery Date','type'=>$delivDate, '3'=>'Delivery Term', '4'=>$delivTerm,'5'=>'Terms', '6'=>$payTerm . ' Hari')
			
		);
		$this->cezpdf->ezTable($data2
								,array('name'=>'','type'=>'','3'=>'','4'=>'','5'=>'','6'=>''),''
								,array('showHeadings'=>0, 'showLines'=>2,'shaded'=>1,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>530.28));
		
		$data4 = array(
			
			array('name'=>'','type'=>'')
			
			
		);
		$this->cezpdf->ezTable($data4
								,array('name'=>'','type'=>''),''
								,array('showHeadings'=>0, 'showLines'=>0,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>400.28, 'col'=>array('justification'=>'right')));
										
		$data3 = array(
			array('name'=>'1','type'=>'CAR15', '3'=>'Mobil pemilik: Blue Star Toyota Vios Silver', '4'=>'1,500,000','5'=>'1', '6'=>'88,000', '7'=>'1,380,000')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			,array('name'=>'','type'=>'', '3'=>'', '4'=>'','5'=>'', '6'=>'', '7'=>'')
			
			
		);
		$this->cezpdf->ezTable($data3
								,array('name'=>'No.','type'=>'ID','3'=>'SKU/Deskripsi','4'=>'Unit Price','5'=>'Qty','6'=>'Discount', '7'=>'Amount'),''
								,array('showHeadings'=>1, 'showLines'=>1,'shaded'=>0,'xPos'=>'right'
										,'xOrientation'=>'left','width'=>530.28));
		$this->cezpdf->ezSetDy(-8);
		
		$this->cezpdf->ezText('Note : ', '10');			
		$this->cezpdf->ezText($note['0']['note'], '10');
		
		$this->cezpdf->addTextWrap('330','230','100','10','Subtotal:','right','0');
		$this->cezpdf->addTextWrap('460','230','100','10','1,500,000.00','right','0');
		$this->cezpdf->addTextWrap('330','215','100','10','Total Discount:','right','0');
		$this->cezpdf->addTextWrap('460','215','100','10','88,000.00','right','0');	
		$this->cezpdf->addTextWrap('330','200','100','10','VAT/PPN (10%):','right','0');
		$this->cezpdf->addTextWrap('460','200','100','10','150,000.00','right','0');
		$this->cezpdf->addTextWrap('330','185','100','10','Withholding Tax(2%):','right','0');
		$this->cezpdf->addTextWrap('460','185','100','10','30,000.00','right','0');
		$this->cezpdf->addTextWrap('460','170','100','10','1,532,000.00','right','0');		
		$this->cezpdf->addTextWrap('330','155','100','10','Shipping:','right','0');
		$this->cezpdf->addTextWrap('460','155','100','10','7000.00','right','0');	
		$this->cezpdf->setLineStyle(1);						
		$this->cezpdf->line(360,145,560,145);		
		$this->cezpdf->addTextWrap('330','130','100','10','<b>Total:</b>','right','0');
		$this->cezpdf->addTextWrap('460','130','100','10','1,539,000.00','right','0');	
		$this->cezpdf->addTextWrap('330','115','100','10','Deposit:','right','0');
		$this->cezpdf->addTextWrap('460','115','100','10','0.00','right','0');	
		$this->cezpdf->addTextWrap('330','100','100','10','<b>Amount Due:</b>','right','0');
		$this->cezpdf->addTextWrap('460','100','100','10','1,539,000.00','right','0');
		$this->cezpdf->addTextWrap('40','85','100','10','Authorized Signature,','left','0');
		$this->cezpdf->line(40,35,180,35);	
		prep_pdf(); 
		//$this->cezpdf->ezStream();
		
					
		print $this->cezpdf->output();
		//echo "<meta http-equiv='Refresh' content='0; URL=/'>";
	
	}
	
	
}